// @ts-nocheck
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { useSendCommand } from '@/api/gps/gps'
import { clearAlarm } from '@/api/gps/alarm'
import { ElMessage } from 'element-plus'
import { getDictLabelList } from '@/utils/tool'
import { storeToRefs } from 'pinia'
import useDeviceStore from '@/store/gps/device'
const deviceStore = useDeviceStore()
const { checkedDeviceList, checkedDeviceImeiList, checkedDeviceImei } = storeToRefs(deviceStore)

const dialogVisible = ref(false)
const warningList = ref<any[]>([])
const dataForm = reactive<any>({
  cmdTypeStr: '',
  cmdDesc: null,
  cmdIsSync: null,
  cmdNeedPwd: null,
  cmdParams: null,
  cmdType: null,
  params: '',
  cmdPwd: '',
  cmdCacheSec: ''
})

const btnLoading = ref(false)
function init(imei) {
  dialogVisible.value = true
  let a = checkedDeviceList.value[checkedDeviceImei.value]
  // console.log(a)
  warningList.value = a.alarms
}

function handleClose() {
  dialogVisible.value = false
}

function processAlarm(alarm: string) {
  clearAlarm(checkedDeviceImei.value, alarm)
    .then((res: any) => {
      if (res.code === 0) {
        let index = warningList.value.indexOf(alarm)
        if (index !== -1) {
          warningList.value.splice(index, 1)
        }
      } else {
        ElMessage.error(res.msg)
      }
    })
    .finally(() => {})
}

defineExpose({
  init
})
</script>

<template>
  <el-dialog
    v-model="dialogVisible"
    title="当前报警"
    width="400px"
    append-to-body
    destroy-on-close
    @close="handleClose">
    <div class="s_raido">
      <el-table :data="warningList" class="layout-table" height="400">
        <!-- <ma-dict-column prop="status" label="报警类型" dict-type="alarm_type"></ma-dict-column> -->
        <el-table-column label="报警类型" header-align="center" align="center">
          <template #default="{ row }">
            <!-- <ma-dict-label dict-type="alarm_type" :dict-value="row" /> -->
            <span v-html="getDictLabelList('alarm_type', row)"></span>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" header-align="center" align="center" width="80">
          <template #default="scope">
            <el-button type="primary" link @click="processAlarm(scope.row)">处理</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <template #footer>
      <el-button @click="handleClose">取消</el-button>
    </template>
  </el-dialog>
</template>

<style scoped lang="scss"></style>
